package com.dragon.modules.yuegou.service.impl.member;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.modules.yuegou.entity.member.TemplatePretendEntity;
import com.dragon.modules.yuegou.mapper.member.TemplatePretendMapper;
import com.dragon.modules.yuegou.model.member.TemplatePretend;
import com.dragon.modules.yuegou.query.member.TemplatePretendQuery;
import com.dragon.modules.yuegou.service.member.TemplatePretendService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 会员卡等级装扮 服务实现
 *
 * @author pbuilder generated
 * @date 2021-12-15 11:38:52
 * @version 2.0
 */
@Service("memTemplatePretendService")
public class TemplatePretendServiceImpl
		extends ServiceImpl<TemplatePretendMapper, TemplatePretendEntity>
		implements TemplatePretendService {

	@Override
	public void saveTemplatePretend(TemplatePretend pretend) {
		if(StringUtils.isNotBlank(pretend.getId())) {
			baseMapper.updateById(pretend);
		}else {
			pretend.setId(IdWorker.getIdStr());
			save(pretend);
		}
	}

	@Override
	public TemplatePretend getFirst(TemplatePretendQuery templatePretendQuery){
		List<TemplatePretendEntity> list = baseMapper.selectList(templatePretendQuery.toQueryWrapper());
		if (CollectionUtils.isNotEmpty(list)){
			return new TemplatePretend(list.get(0));
		}

		return new TemplatePretend();
	}

}